package com.ruoyi.dynamic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.dynamic.mapper.LuckyBagUserMapper;
import com.ruoyi.dynamic.model.constant.DynamicConstant;
import com.ruoyi.dynamic.model.enums.LuckyBagWayEnums;
import com.ruoyi.dynamic.model.pojo.entity.LuckyBagUser;
import com.ruoyi.dynamic.service.ILuckyBagUserService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 福袋参与用户 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2024-11-28
 */
@Service
public class LuckyBagUserServiceImpl extends ServiceImpl<LuckyBagUserMapper, LuckyBagUser> implements ILuckyBagUserService {

    @Override
    public void addRecord(Long userId, Long roomId, String remark, String nickName, String photo, Integer partWay, Long id) {
        LuckyBagUser luckyBagUser = new LuckyBagUser();
        luckyBagUser.setRoomId(roomId);
        luckyBagUser.setUserId(userId);
        luckyBagUser.setRemark(remark);
        luckyBagUser.setMoney(BigDecimal.ZERO);
        luckyBagUser.setCreateTime(new Date());
        luckyBagUser.setUserNickName(nickName);
        luckyBagUser.setUserPhoto(photo);
        luckyBagUser.setPartWayName(LuckyBagWayEnums.getName(partWay));
        luckyBagUser.setLuckyBagId(id);
        luckyBagUser.setIsWinner(DynamicConstant.CheckStatus.NO);
        save(luckyBagUser);
    }

    @Override
    public List<LuckyBagUser> getUserListId(Long luckId) {
        return lambdaQuery().eq(LuckyBagUser::getLuckyBagId, luckId).list();
    }

    @Override
    public boolean isJoinByUser(Long id, Long userId) {
        return lambdaQuery()
                .eq(LuckyBagUser::getLuckyBagId, id)
                .eq(LuckyBagUser::getUserId, userId).count() > 0;
    }
}
